#include <iostream>
#include <vector>
#include<tuple>
using namespace std;


// 已知
int Q;
int N, p, a, b, x;
// 未知
int sum = 0;
int maxn = 0;
vector<tuple<int, int, int>> presents(11111);
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> p >> a >> b;
        sum += b;
        maxn = max(maxn, a);
        presents[i] = { p,a, b };
    }

    cin >> Q;
    while (Q--)
    {
        cin >> x;
        if (x > sum + maxn) cout << x - sum << '\n'; // 如果x都超过所有的b之和了，那他造不成什么影响
        else
        {
            for (auto [p, a, b] : presents)
            {
                if (x <= p) x += a;
                else x = max(0, x - b);
            }
            cout << x << '\n';
        }
    }

    return 0;
}